package com.example.capsule_chat0322.file;



import com.example.capsule_chat0322.bean.MessageBean;
import com.example.capsule_chat0322.netty.NettyClient;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
 * @Author: zhuzhiming
 * @Date: 2022/4/27 20:15
 */

public class FileClient {


    private NettyClient nettyClient;

    public FileClient(NettyClient nettyClient) {
        this.nettyClient = nettyClient;
    }

    public void uploadFile(String filePath) throws IOException {

        File file = new File(filePath);

        if (file.isFile() && file.exists()) {
            MessageBean messageBean = new MessageBean();
            byte[] fileByteArr = new byte[(int) file.length()];
            RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");

//            if (randomAccessFile.read(fileByteArr) != -1) {
//                messageBean.setBytes(fileByteArr);
//            }
            messageBean.setMsgType(1);
            messageBean.setFileName(file.getName());
            nettyClient.sendMessage(messageBean);


        }
    }

}
